package Guava;

import com.google.common.base.Strings;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Grup:Guava
 * @Auther:cola
 * @Data:2021/3/30-2021-03-15:03
 * @version:1.0
 */
public class GuavaDemo {

    /*
     *
     * 设置 转换
     * */
    @Test
    public void testGuva3() {
        Set<Long> timeset = Sets.newHashSet(20121212L, 20170520L, 20160808L);
        Collection<Object> timecollect = Collections2.transform(timeset, e -> new SimpleDateFormat("yyyy-MM-dd").format(e));
        timecollect.forEach(System.out::println);

    }


    /*
     *
     * 设置过滤器
     * */
    @Test
    public void testGuva2() {
        List<String> list = Lists.newArrayList("java", "php", "h5");
        Collection<String> result = Collections2.filter(list, e -> e.startsWith("j"));
        result.forEach(System.out::println);
    }

    /*
     * 设置只读
     * */
    @Test
    public void testGuava1() {
        System.out.println("test guava");
        //List<String>list= Arrays.asList("javk","afaf","ccc");
        //list.add("cola");
        List<String> list = new ArrayList<>();
        list.add("jack");
        list.add("tom");
        list.add("cola");
        //List<String> readlist= Collections.unmodifiableList(list);
        //readlist.add("cc");
        //ImmutableList<String> ilist=ImmutableList.of("jack","tom","lily","vola");
        //ilist.add("cc");

    }
}
